package main

import (
	"time"
	"fmt"
)

func main() {
	requests:=make(chan int,5)

	for i:=1;i<=5;i++{
		requests<-i
	}

	close(requests)

	limiter:=time.Tick(time.Millisecond*200)

	for req:=range requests{
		<-limiter
		fmt.Println(" limiter request:",req,time.Now())
	}



	//########################################
	burstyLimiter:=make(chan time.Time,3)

	for i:=0;i<3;i++{
		burstyLimiter<-time.Now()
	}

	go func() {
		for t:=range time.Tick(time.Millisecond*200){
			fmt.Println("t",t)
			burstyLimiter<-t
		}
	}()

	burstyRequsts:=make(chan int,5)
	for i:=1;i<=5;i++{
		burstyRequsts<-i
	}

	close(burstyRequsts)

	for req:=range burstyRequsts{
		<-burstyLimiter
		fmt.Println("burstyRequsts:",req,time.Now())
	}


}